package com.estar.integaration.Impl.paymentPlanimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estar.integaration.Mapper.paymentPlanMapper.SupplierAccountPeriodMapper;
import com.estar.integaration.Service.paymentPlanService.ISupplierAccountPeriodService;
import com.estar.integaration.entity.paymentPlanEntity.SupplierAccountPeriod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YJL
 * @since 2022-02-15
 */
@Service
public class SupplierAccountPeriodServiceImpl extends ServiceImpl<SupplierAccountPeriodMapper, SupplierAccountPeriod> implements ISupplierAccountPeriodService {

  @Autowired
  SupplierAccountPeriodMapper supplierAccountPeriodMapper;

  @Override
  public List<SupplierAccountPeriod> getAllSupplierAccountPeriod() {
    return supplierAccountPeriodMapper.selectList(null);
  }

  @Override
  public void updateDayBySuppliername(String supplierName, Integer day) {
    QueryWrapper queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("supplier_name",supplierName);
    SupplierAccountPeriod supplierAccountPeriod = supplierAccountPeriodMapper.selectOne(queryWrapper);
    supplierAccountPeriod.setRealNeedAddDay(String.valueOf(day));
    supplierAccountPeriodMapper.updateById(supplierAccountPeriod);
  }

  @Override
  public void deleteBySupplierName(String supplierName) {
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq("supplier_name",supplierName);
    supplierAccountPeriodMapper.delete(queryWrapper);
  }

  @Override
  public List<SupplierAccountPeriod> getSupplierByName(String supplierName) {
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq("supplier_name",supplierName);
    List<SupplierAccountPeriod> supplierAccountPeriodList = supplierAccountPeriodMapper.selectList(queryWrapper);
    return supplierAccountPeriodList;
  }


}
